package it.desertsupport.hibernate.dao;

import it.desertsupport.model.Profile;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

public class ProfileDAOImpl extends BaseHibernateDAO implements ProfileDAO {

	@Override
	public void save(Profile profile) throws Exception {
		getSession().save(profile);
	}

	@Override
	public void delete(Profile profile) throws Exception {
		getSession().delete(profile);
	}

	@Override
	public Profile getProfile(Long id) throws Exception {
		return (Profile) getSession().get(Profile.class, id);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Profile> findAll() throws Exception {
		String queryString = "from Profile";
		Query queryObject = getSession().createQuery(queryString);
		return queryObject.list();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Profile> findByExample(Profile profile) throws Exception {
		Criteria cri = getSession().createCriteria(Profile.class);
		cri.add(Example.create(profile));
		return cri.list();
	}

	@Override
	public Profile marge(Profile profile) throws Exception {
		return (Profile) getSession().merge(profile);
	}

}
